<template>
	<view class="container">
		<image class="xixi" :src="'http://localhost:8090'+user.icon" @click="dingzheng"></image>
		<uni-list>
			<uni-list-item title="修改密码" v-show="!flg"></uni-list-item>
			<uni-list-item title="电话" v-show="!flg" :rightText="user.telephone"></uni-list-item>
		</uni-list>
		<button type="primary" @click="login" v-show="flg">登录</button>
		<button type="default" v-show="!flg" @click="out">退出登录</button>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				flg:true,
				user:{
					
				}
			}
		},
		methods: {
		login() {
			uni.navigateTo({
				url: "login/login"
			})
		
		},
		out() {
			this.flg = true,
			this.user={},
			uni.clearStorageSync("user")
		
		},
		dingzheng() {
			if(!this.flg){
			uni.chooseImage({
				success: (res) => {
					console.log(res);
					if(res.tempFilePaths.length>0){
						let tempFilePaths = res.tempFilePaths[0]
						let tempFiles=res.tempFiles[0]
						uni.uploadFile({
							url: "http://localhost:8090/foodapp/uploadheadicon",
							filePath:tempFilePaths,
							name:'file',
							formData:{
								"file":tempFiles,
								"id":1
							},
							success:(uploadres)=>{
								let person=JSON.parse(uploadres.data)
								this.user.icon=person.headiconpath
								console.log(this.user.icon);
							},
							fail(err){
								console(err);
							}
						})
					}
					
				}
			})
			}
		}	
		},
		onLoad: () => {
			uni.onTabBarMidButtonTap(function(e) {
				console.log(e)
			})
		},
		onShow() {
					this.user=uni.getStorageSync("user")
		if(this.user!=""&&this.user!=null){
			 this.flg=false
		}
			
				}
	}
</script>

<style>
	.xixi {
		border: 1px solid #FFD700;
		width: 50px;
		height: 50px;
		border-radius: 100%;
		background: #FFD700;
	}
</style>
